package com.example.controller;

import com.csq.User;
import com.example.feignService.UserFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 登录类
 */
@RestController
public class LoginController {

    @Autowired
    private UserFeignService userFeignService;

    @RequestMapping(value = "login", method = RequestMethod.GET)
    public String login(@RequestParam("name") String name, @RequestParam("pwd") String pwd, HttpServletRequest request){
        User user = new User();
        user.setUsername(name);
        user.setPassword(pwd);
        String result = userFeignService.login(user);
        //登录成功后，将对象保存到session中
        request.getSession().setAttribute("user", user);
        return  "请求结果：" + result;
    }
}
